package com.gimi.cloud.bbp.client.controller.mall;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gimi.cloud.bbp.client.service.mall.MallMessageService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.mall.MallMessageDTO;

@Controller
@RequestMapping("/mall/message")
public class MallMessageController {
	
	@Autowired private MallMessageService service;
	
	/**
	 * 获取消息列表
	 * @param mallMessageDTO
	 * @param response
	 */
	@RequestMapping("/getMessageListByReceiveUser")
	public void getMessageListByReceiveUser(@RequestBody MallMessageDTO mallMessageDTO, HttpServletResponse response) {
		Util.sendResponseFastJson(service.getMessageListByReceiveUser(mallMessageDTO), ResponseCodeEnum.SUCCESSED, response);
	}
	
	/**
	 * 用户删除消息列表
	 * @param mallMessageDTO
	 * @param response
	 */
	@RequestMapping("/userDelMessageByMeId")
	public void userDelMessageByMeId(@RequestBody MallMessageDTO mallMessageDTO, HttpServletResponse response) {
		service.userDelMessageByMeId(mallMessageDTO);
		Util.sendResponseFastJson(null, ResponseCodeEnum.SUCCESSED, response);
	}
	
	/**
	 * 通过ID获取消息详情
	 * @param mallMessageDTO
	 * @param response
	 */
	@RequestMapping("/getMessageByMeId")
	public void getMessageByMeId(@RequestBody MallMessageDTO mallMessageDTO, HttpServletResponse response) {
		Util.sendResponseFastJson(service.getMessageByMeId(mallMessageDTO), ResponseCodeEnum.SUCCESSED, response);
	}
	
	/**
	 * 获取未读消息条数
	 * @param mallMessageDTO
	 * @param response
	 */
	@RequestMapping("/getMessageByUserIdAndStatus")
	public void getMessageByUserIdAndStatus(@RequestBody MallMessageDTO mallMessageDTO, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("count", service.getMessageByUserIdAndStatus(mallMessageDTO));
		Util.sendResponseFastJson(resultMap, ResponseCodeEnum.SUCCESSED, response);
	}

}
